﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace Logika
{
    class Zoga
    {
        private Point pos;
        private int smer;
        private Point spawn;
        private int hitrost;

        public Zoga()
        {
            pos = new Point();
            smer = 0;
            spawn = new Point();
        }

        public Zoga(Point pos, int smer, Point spawn, int hitrost)
        {
            this.pos = pos;
            this.smer = smer;
            this.spawn = spawn;
            this.hitrost = hitrost;
        }

        public void premik()
        {
            switch (smer)
            {
                case 0:
                    if (!isFree(new Point(pos.X - 1, pos.Y - 1)))
                    {
                        if (isFree(new Point(pos.X + 1, pos.Y - 1))) smer = 1;
                        else if (!isFree(new Point(pos.X - 1, pos.Y + 1))) smer = 3;
                        else smer = 4;
                    }
                    break;
                case 1:
                    if (!isFree(new Point(pos.X + 1, pos.Y - 1)))
                    {
                        if (isFree(new Point(pos.X + 1, pos.Y + 1))) smer = 2;
                        else if (!isFree(new Point(pos.X - 1, pos.Y - 1))) smer = 0;
                        else smer = 3;
                    }
                    break;
                case 2:
                    if (!isFree(new Point(pos.X + 1, pos.Y + 1)))
                    {
                        if (isFree(new Point(pos.X - 1, pos.Y + 1))) smer = 3;
                        else if (!isFree(new Point(pos.X + 1, pos.Y - 1))) smer = 1;
                        else smer = 0;
                    }
                    break;
                case 3:
                    if (!isFree(new Point(pos.X - 1, pos.Y + 1)))
                    {
                        if (isFree(new Point(pos.X - 1, pos.Y - 1))) smer = 0;
                        else if (!isFree(new Point(pos.X + 1, pos.Y + 1))) smer = 2;
                        else smer = 1;
                    }
                    break;
            }
            if (smer == 0 || smer == 3) pos.X -= 1;
            else pos.X += 1;
            if (smer == 0 || smer == 1) pos.Y -= 1;
            else pos.Y += 1;
        }

        public void setSmer(int smer)
        {
            this.smer = smer;
        }

        public int getSmer()
        {
            return smer;
        }

        public void setSpawn(Point spawn)
        {
            this.spawn = spawn;
        }

        public Point getSpawn()
        {
            return spawn;
        }

        public void setHitrost(int hitrost)
        {
            this.hitrost = hitrost;
        }

        public int getHitrost()
        {
            return hitrost;
        }

        public bool isFree(Point p) 
        {
            return true;
        }
    }
}
